/**
 * 
 */
package br.com.projetospring.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.projetospring.entity.Usuario;

/**
 * @author Joelson
 *
 */
@Component
@Repository("usuarioDao")
public class UsuarioDao {
	
	@PersistenceContext
	protected EntityManager em;
	
	@Transactional
	public List<Usuario> buscarTodos(){
		
		String jpql = "select t from Usuario t order by t.nome ";		
		Query query = em.createQuery(jpql);		
		List<Usuario> usuarios = (List<Usuario>) query.getResultList();
		
		return usuarios;		
	}	

	public EntityManager getEm() {
		return em;
	}

	public void setEm(EntityManager em) {
		this.em = em;
	}
	
	
	
}
